package com.qf.controller;

import com.qf.pojo.User;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Repository;
import org.springframework.web.bind.annotation.*;

import javax.servlet.ServletRequest;
import java.util.Arrays;
import java.util.List;

/*
 *@Description:
 *@author:刘哥
 *@Date:86180 2022/8/29 19:00
 */
//表名这个类是controller类
@Controller
//设置前端的请求路径
@RequestMapping("/test")
public class TestController {
    @RequestMapping("")
    public void test01(ServletRequest request){
        String username = request.getParameter("username");
        String password = request.getParameter("password");
        System.out.println(username+"=======>"+ password);
    }
    @RequestMapping("/test02")
    public void test02(String username,String password){
        System.out.println(username+"=======>"+ password);
    }
    @RequestMapping("/test03")
//    @RequestParam(name：可以给前端参数指定别名,defaultValue参数可以个参数指定默认值)
    public String test03(@RequestParam(name = "username") String name, String password, @RequestParam(defaultValue = "18")String age){
        System.out.println(name+"=======>"+ password+"========>"+age);
        return "/dhas";
    }
    @RequestMapping("/test04")
    public String test04(User user){
        System.out.println(user);
        return "/dhas";
    }
    @RequestMapping("/test05")
    @ResponseBody
    public String test05(String[] hobby){
        System.out.println(Arrays.toString(hobby));
        return Arrays.toString(hobby);
    }
    @RequestMapping("/test06")
//    @ResponseBody
    public void test06(List<String> hobby){
        System.out.println("hobby = " + hobby);
    }

    @RequestMapping("/test07/{userId}")
    public void test07(@PathVariable("userId") Integer userId){
        System.out.println("userId = " + userId);
    }

    @RequestMapping("/test08/{userId}/aaa/{username}/{password}")
    public void test08(@PathVariable("userId") Integer userId,@PathVariable("username") String username,@PathVariable("password") String pass){
        System.out.println("userId = " + userId);
        System.out.println("username = " + username);
        System.out.println("pass = " + pass);
    }

}
